package com.pet.common.core.domain.entity;

import com.pet.common.annotation.Excel;
import com.pet.common.annotation.Excel.ColumnType;
import com.pet.common.annotation.Excel.Type;
import com.pet.common.annotation.Excels;
import com.pet.common.core.domain.BaseEntity;
import com.pet.common.xss.Xss;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

/**
 * 用户对象 sys_user
 *
 * @author pet
 */
public class SysUser extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
    private Long userId;

    /**
     * 部门ID
     */
    @Excel(name = "部门编号", type = Type.IMPORT)
    private Long deptId;

    /**
     * 商家名称
     */
    @Excel(name = "商家名称")
    private String merchantName;

    /**
     * 商家说明
     */
    @Excel(name = "商家说明")
    private String merchantTips;

    /**
     * 商家说明
     */
    @Excel(name = "地址")
    private String address;

    /**
     * 商家微信
     */
    @Excel(name = "商家微信")
    private String wechat;

    /**
     * 商家电话
     */
    @Excel(name = "商家登录电话")
    private String mobile;

    /**
     * 商家电话
     */
    @Excel(name = "商家预留电话")
    private String contactMobile;

    /**
     * 商家码
     */
    @Excel(name = "商家码")
    private String merchantCode;

    /**
     * 密码
     */
    private String password;

    /**
     * 部门对象
     */
    @Excels({
            @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
            @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
    })
    private SysDept dept;

    /**
     * 角色对象
     */
    private List<SysRole> roles;

    /**
     * 角色组
     */
    private Long[] roleIds;

    /**
     * 岗位组
     */
    private Long[] postIds;

    /**
     * 角色ID
     */
    private Long roleId;

    public SysUser() {

    }

    public SysUser(Long userId) {
        this.userId = userId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    public Long getDeptId() {
        return deptId;
    }

    public void setDeptId(Long deptId) {
        this.deptId = deptId;
    }

    public void setMerchantName(String merchantName) {
        this.merchantName = merchantName;
    }

    public String getMerchantName() {
        return merchantName;
    }

    public void setMerchantTips(String merchantTips) {
        this.merchantTips = merchantTips;
    }

    public String getMerchantTips() {
        return merchantTips;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddress() {
        return address;
    }

    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    public String getWechat() {
        return wechat;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    @NotBlank(message = "登录手机号码不能为空")
    public String getMobile() {
        return mobile;
    }

    public String getContactMobile() {
        return contactMobile;
    }

    public void setContactMobile(String contactMobile) {
        this.contactMobile = contactMobile;
    }

    public void setMerchantCode(String merchantCode) {
        this.merchantCode = merchantCode;
    }

    public String getMerchantCode() {
        return merchantCode;
    }

    @NotBlank(message = "密码不能为空")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public SysDept getDept() {
        return dept;
    }

    public void setDept(SysDept dept) {
        this.dept = dept;
    }

    public List<SysRole> getRoles() {
        return roles;
    }

    public void setRoles(List<SysRole> roles) {
        this.roles = roles;
    }

    public Long[] getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(Long[] roleIds) {
        this.roleIds = roleIds;
    }

    public Long[] getPostIds() {
        return postIds;
    }

    public void setPostIds(Long[] postIds) {
        this.postIds = postIds;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    @Override
    public String toString() {
        return "SysUser{" +
                "userId=" + userId +
                ", deptId=" + deptId +
                ", merchantName='" + merchantName + '\'' +
                ", merchantTips='" + merchantTips + '\'' +
                ", address='" + address + '\'' +
                ", wechat='" + wechat + '\'' +
                ", mobile='" + mobile + '\'' +
                ", merchantCode='" + merchantCode + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}
